package com.itkaige.boot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpSession;

@Controller
//******************若使用@RestController无法跳转为html页面*******************

public class LoginController {

//    @RequestMapping("/index.html")
//    public String index(){
//        return "index";
//    }
    @RequestMapping("/user/login")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Model model,HttpSession session){

        session.setAttribute("loginUser",username);
        if("123".equals(username)&&"123".equals(password)){
            return "redirect:/dashboard.html";
        }else {
            model.addAttribute("msg","用户名或密码错误！");
            return "index";
        }

    }
}
